package org.jmh.gift.controller;

import org.jmh.gift.service.IGoodsSafeguardService;
import org.jmh.gift.domain.GoodsSafeguard;
import org.jmh.gift.query.GoodsSafeguardQuery;
import org.jmh.gift.util.AjaxResult;
import org.jmh.gift.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.baomidou.mybatisplus.plugins.Page;
@RestController
@RequestMapping("/goodsSafeguard")
public class GoodsSafeguardController {
    @Autowired
    public IGoodsSafeguardService goodsSafeguardService;


    /**
     * 保存和修改公用的
     * @param goodsSafeguard  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody GoodsSafeguard goodsSafeguard){

            if( goodsSafeguard.getId()!=null)
                goodsSafeguardService.updateById(goodsSafeguard);
            else
                goodsSafeguardService.insert(goodsSafeguard);
            return AjaxResult.success();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
            goodsSafeguardService.deleteById(id);
            return AjaxResult.success();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id")Long id)
    {
            GoodsSafeguard goodsSafeguard = goodsSafeguardService.selectById(id);
            return AjaxResult.success(goodsSafeguard);

    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult list(){

            List< GoodsSafeguard> list = goodsSafeguardService.selectList(null);
            return AjaxResult.success(list);

    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult json(@RequestBody GoodsSafeguardQuery query)
    {

        Page<GoodsSafeguard> page = new Page<GoodsSafeguard>(query.getPage(),query.getRows());
        page = goodsSafeguardService.selectPage(page);
        PageList pageList = new PageList<GoodsSafeguard>(page.getTotal(),page.getRecords());
            return AjaxResult.success(pageList);

    }




}
